package com.hbm.usercenter.activity;

import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.hbm.usercenter.R;
import com.hbm.usercenter.base.BaseActivityCommon;
import com.hbm.usercenter.fragment.ListApplyFragment;
import com.hbm.usercenter.fragment.ListCheckFragment;
import com.hbm.usercenter.utils.LogUtils;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class MyApplyActivity extends BaseActivityCommon {

    @Bind(R.id.tv_apply)
    TextView mTvApply;
    @Bind(R.id.tv_to_check)
    TextView mTvToCheck;
    @Bind(R.id.fl_content)
    FrameLayout mFlContent;

    private ListApplyFragment mListApplyFragment;
    private ListCheckFragment mListCheckFragment;
    private FragmentTransaction mTransaction;

    @Override
    protected void initView() {
        setContentView(R.layout.activity_my_apply);
        ButterKnife.bind(this);
        initToolbar("我的申请");

        setSelect(0);
        mTvApply.setBackgroundColor(0xFFF1F1F1);
    }

    @OnClick({R.id.tv_apply, R.id.tv_to_check})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_apply:
                mTvApply.setBackgroundColor(0xFFF1F1F1);
                mTvToCheck.setBackgroundColor(0xFFFAFAFA);

                setSelect(0);
                break;
            case R.id.tv_to_check:
                mTvToCheck.setBackgroundColor(0xFFF1F1F1);
                mTvApply.setBackgroundColor(0xFFFAFAFA);

                setSelect(1);
                break;
        }
    }

    public void setSelect(int select) {
        FragmentManager mFragmentManager = getSupportFragmentManager();
        mTransaction = mFragmentManager.beginTransaction();
        hideFragment();
        switch (select) {
            case 0:
                if (mListApplyFragment == null) {
                    mListApplyFragment = new ListApplyFragment();

                    mTransaction.add(R.id.fl_content, mListApplyFragment);
                }
                mTransaction.show(mListApplyFragment);
                break;

            case 1:
                if (mListCheckFragment == null) {
                    mListCheckFragment = new ListCheckFragment();
                    mTransaction.add(R.id.fl_content, mListCheckFragment);
                }
                mTransaction.show(mListCheckFragment);
                break;
        }
        mTransaction.commit();
    }

    private void hideFragment() {
        if (mListApplyFragment != null) {
            mTransaction.hide(mListApplyFragment);
        }
        if (mListCheckFragment != null) {
            mTransaction.hide(mListCheckFragment);
        }
    }


}
